<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page_Model extends CI_Model {
 
   function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
	
	public function GetPage($key)
	{
		$query = "SELECT
					psacar_page.id AS Id,
					psacar_page.parent_id AS ParentId,
					psacar_page.title AS Title,
					psacar_page.`name` AS Name,
					psacar_page.description AS Description,
					psacar_page.show_menu AS ShowMenu,
					psacar_page.is_show AS IsShow
				FROM
					psacar_page 
				WHERE psacar_page.keyword = '" . $key . "' " .
                        "ORDER BY name";
		$result=$this->db->query($query);
		return  $result;
	}
	
	public function GetPageListByParent($ParentId)
	{
		$query = "SELECT
					psacar_page.id AS Id,
					psacar_page.title AS Title,
					psacar_page.`name` AS Name,
					psacar_page.short_description AS ShortDesc,
					psacar_page.description AS Description,
					psacar_page.show_menu AS ShowMenu,
					psacar_page.is_show AS IsShow
				FROM
					psacar_page 
				WHERE psacar_page.parent_id = " . $ParentId . 
                        " ORDER BY name";
		$result=$this->db->query($query);
		return  $result;
	}
	
	public function GetPageById($Id)
	{
		$query = "SELECT
					psacar_page.title AS Title,
					psacar_page.`name` AS Name,
					psacar_page.description AS Description,
					psacar_page.show_menu AS ShowMenu,
					psacar_page.is_show AS IsShow
				FROM
					psacar_page 
				WHERE psacar_page.id = " . $Id;
		$result=$this->db->query($query);
		return  $result;
	}
        
	public function get_page_by_name($name)
	{
            $query = 
                "SELECT
                    psacar_page.id AS Id,
                    psacar_page.parent_id AS ParentId,
                    psacar_page.title AS Title,
                    psacar_page.`name` AS Name,
                    psacar_page.description AS Description,
                    psacar_page.show_menu AS ShowMenu,
                    psacar_page.is_show AS IsShow
                FROM
                    psacar_page 
                WHERE 
                    psacar_page.name like '%" . $name . "%' " .
                "ORDER BY name";
            $result = $this->db->query($query);
            return  $result;
	}        
}